package com.autumn.annotations.bean.config;

import com.autumn.annotations.bean.config.condition.LinuxCondition;
import com.autumn.annotations.bean.config.condition.OSCondition;
import com.autumn.annotations.bean.config.condition.WindowsCondition;
import com.autumn.annotations.demos.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: ConditionalDemoConfig
 *
 * @Description:
 * @Author: wangqiuyang
 * @Date: 2021/12/28 下午5:16
 * History:
 * <author>          <time>          <version>          <desc>
 * wangqiuyang    2021/12/28 下午5:16   @Version 1.0        描述
 */
@Configuration
@Conditional({OSCondition.class}) // 如果放在类上则代表 类中所有的bean 都执行这个规则
public class ConditionalDemoConfig {

    @Bean(value = "person")
    Person person1 (){
        System.out.println("person ... 单实例");
        return new Person("person",18);
    }

    @Conditional({WindowsCondition.class})
    @Bean(value = "bill")
    Person person2 (){
        System.out.println("bill gus ... 单实例");
        return new Person("bill gates",18);
    }

    @Conditional({LinuxCondition.class})
    @Bean(value = "linus")
    Person person3 (){
        System.out.println("linus ... 单实例");
        return new Person("linus",18);
    }
}
